package edu.uic.cs.i422.s2011.team4;

import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

public class EmailActivity extends Activity implements OnClickListener {

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
	      View inflatedView = View.inflate(this, R.layout.emailact, null);
	        SquirrelUIGenerator squirrel = new SquirrelUIGenerator(this);
	        squirrel.setTitle(R.string.emailTitle);
	        squirrel.setHelp(R.string.emailHelp);
	        squirrel.setBreadCrumb(R.string.emailBreadCrumb);
	        LinearLayout layout = new LinearLayout(this);
	        layout.setOrientation(LinearLayout.VERTICAL); //Set Orientation
	        layout.addView(squirrel.getHeader());
	        layout.addView(inflatedView);
	        setContentView(layout);
	        
		final  Button doneButton = (Button) findViewById(R.id.email_done);
		doneButton.setOnClickListener(this);	
		
		 final EditText editText = (EditText)findViewById(R.id.editEmail);
		 
		 Account[] accounts = AccountManager.get(this).getAccounts();
		 for (Account account : accounts) {
		   // TODO: Check possibleEmail against an email regex or treat
		   // account.name as an email address only for certain account.type values.
		   String possibleEmail = account.name;
		   editText.setText(possibleEmail);
		 }

	       
	        editText.addTextChangedListener(new TextWatcher(){

				public void afterTextChanged(Editable s) {
					// TODO Auto-generated method stub
				}

				public void beforeTextChanged(CharSequence s, int start,
						int count, int after) {
					// TODO Auto-generated method stub
					
				}

				public void onTextChanged(CharSequence s, int start,
						int before, int count) {
					// TODO Auto-generated method stub
					
				}});
	}
	public void onClick(View v) {
		SquirrelData.setEmailCheckMark(true);
		finish();
	}
}
